package com.xiaoxx.coin.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum OrderTypesEnum {
    LIMIT("LIMIT", "限价单"),
    MARKET("MARKET", "市价单"),
    STOP("STOP", "止损限价单"),
    STOP_MARKET("STOP_MARKET", "止损市价单"),
    TAKE_PROFIT("TAKE_PROFIT", "止盈限价单"),
    TAKE_PROFIT_MARKET("TAKE_PROFIT_MARKET", "止盈市价单"),
    TRAILING_STOP_MARKET("TRAILING_STOP_MARKET", "跟踪止损单");

    // 订单类型代码
    @EnumValue
    private final String type;
    // 订单类型描述
    private final String description;


    // 根据类型获取枚举
    public static OrderTypesEnum fromType(String type) {
        for (OrderTypesEnum orderType : OrderTypesEnum.values()) {
            if (orderType.getType().equalsIgnoreCase(type)) {
                return orderType;
            }
        }
        throw new IllegalArgumentException("无效的订单类型: " + type);
    }
}
